package com.bingo.mpa.util;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import org.apache.commons.io.IOUtils;

public class HttpClient
{
	public static String get(String urlStr)
	{
		URL url = null;
		HttpURLConnection urlcon = null;
        try
        {
        	 url = new URL(urlStr);
             urlcon = (HttpURLConnection)url.openConnection();
             urlcon.setAllowUserInteraction(false);
             urlcon.setConnectTimeout(30000);
             urlcon.setReadTimeout(30000);
             urlcon.addRequestProperty("Cache-Control", "no-cache");
             urlcon.addRequestProperty("User-Agent", "klksim.com");
             urlcon.connect();
             if(urlcon.getResponseCode() != HttpURLConnection.HTTP_OK)
             	return null;
             InputStream in = urlcon.getInputStream();
             byte[] payload = new byte[in.available()];
             IOUtils.read(in, payload);
             in.close();
             return new String(payload,"UTF-8");
        }
        catch(Exception e)
        {
        	e.printStackTrace();
        }
        finally
        {
        	if(urlcon!=null)urlcon.disconnect();
        }
		return null;
	}
}
